/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bc;

import edu.upn.sigemfi.ope.bc.CargosNotaFacadeLocal;
import edu.upn.sigemfi.ope.be.CargosNota;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Gabo (U)
 */
public class CargosNotaDelegate {

    private CargosNotaFacadeLocal lookupCargosNotaFacade() {
        try {
            Context c = new InitialContext();
            return (CargosNotaFacadeLocal) c.lookup("java:comp/env/CargosNotaFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
    private CargosNotaFacadeLocal local;

    public CargosNotaDelegate(CargosNotaFacadeLocal local) {
        this.local = local;
    }
        public void crear(CargosNota cargosnota) throws Exception {
        try {
            local.create(cargosnota);
        } catch (Exception ex) {
            local = lookupCargosNotaFacade();
            throw new Exception("Crear CargosNota... " + ex.getMessage());
        }
    }
        public void editar(CargosNota cargosnota) throws Exception {
        try {
            local.edit(cargosnota);
        } catch (Exception ex) {
            local = lookupCargosNotaFacade();
            throw new Exception("Editar CargosNota... " + ex.getMessage());
        }
    }
        public void eliminar(CargosNota cargosnota) throws Exception {
        try {
            local.remove(cargosnota);
        } catch (Exception ex) {
            local = lookupCargosNotaFacade();
            throw new Exception("Eliminar CargosNota... " + ex.getMessage());
        }
    }
        public List<CargosNota> getCargosNotas() throws Exception {
        List<CargosNota> cargosnotas;
        try {
            cargosnotas = local.findAll();
        } catch (Exception ex) {
            local = lookupCargosNotaFacade();
            throw new Exception("Listar Efectivos... " + ex.getMessage());
        }
        return cargosnotas;
    }
}
